﻿@{
    ViewBag.Title = "巡检项目设置";
    Layout = "~/Views/Shared/_Form.cshtml";
}
@System.Web.Optimization.Styles.Render("~/Content/scripts/plugins/jqgrid/css")
@System.Web.Optimization.Scripts.Render("~/Content/scripts/plugins/jqgrid/js")
<script>
    var type = request('type');
    $(function () {
        GetGrid();
    });

    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = {};       
        queryJson["TypeId"] = type;
        queryJson["OrganizeId"] = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Polling/GetItemDetailListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
                { label: "名称", name: "Name", index: "Name", width: 150, align: "left" },
                { label: "类别", name: "TypeName", index: "TypeName", width: 150, align: "left" },
                { label: "单位数量", name: "UnitNum", index: "UnitNum", hidden: true },
                {
                    label: "单位", name: "Unit", index: "Unit", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case "0": return "天";
                            case "1": return "周";
                            case "2": return "月";
                            case "3": return "季";
                            case "4": return "年";
                        }
                    }
                },
                {
                    label: "频次", name: "Frenquency", index: "Frenquency", width: 300, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (rowObject.Unit) {
                            case "0": return rowObject.UnitNum + "天" + cellvalue + "次";
                            case "1": return rowObject.UnitNum + "周" + cellvalue + "次";
                            case "2": return rowObject.UnitNum + "月" + cellvalue + "次";
                            case "3": return rowObject.UnitNum + "季" + cellvalue + "次";
                            case "4": return rowObject.UnitNum + "年" + cellvalue + "次";
                        }
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],           
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Code',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                var _ItemName = $("#gridTable").jqGrid('getRowData', row_id)['Name'];
                var subgrid_table_id = subgrid_id + "_t";
                var subhtml = "";
                var queryJson = {};
                queryJson["ItemId"] =  $("#gridTable").jqGrid('getRowData', row_id)['Id'];
                subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
                $("#" + subgrid_id).html(subhtml);
                $("#" + subgrid_table_id).jqGrid({
                    url: "../../PropertyManage/CS_Polling/GetContentListJson",
                    postData: { queryJson: JSON.stringify(queryJson) },
                    datatype: "json",
                    height: 260,
                    autowidth: true,
                    colModel: [
                       { label: "主键", name: "Code", index: "Code", hidden: true },
                    { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
                    { label: "名称", name: "Name", index: "Name", width: 150, align: "left" },
                    {
                        label: "项目名称", name: "Iname", width: 150, align: "left",
                        formatter: function (cellvalue, options, rowObject) {
                            return _ItemName;
                        }

                    },
                    { label: "标准要求", name: "Frenquency", index: "Frenquency", width: 300, align: "left" },
                    { label: "检查方式", name: "Unit", index: "Unit", width: 150, align: "left" },
                    {
                        label: "是否必填", name: "IsNeed", index: "IsNeed", width: 80, align: "center",
                        formatter: function (cellvalue, options, rowObject) {
                            return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }

                    ],
                    rowNum: "10000",
                    sortname: 'Code',
                    caption: "项目下的内容列表",
                    hidegrid: false,
                    shrinkToFit: false,
                    gridview: true
                });
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_Polling/GetItemDetailListJson",
                postData: {
                    type: _typeId,
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_AddItem() {
        dialogOpen({
            id: "ItemForm",
            title: '添加巡检项目',
            url: '/PropertyManage/CS_Polling/ItemForm?typeId=' + type,
            width: "1100px",
            height: "700px",
            btn:null,
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();         
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "ItemForm",
                title: '编辑巡检项目',
                url: '/PropertyManage/CS_Polling/ItemForm?keyValue=' + keyValue + "&typeId=" + type,
                width: "1100px",
                height: "700px",
                btn: null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();  
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_Polling/RemoveItemDetailForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }
  
</script>

<div class="titlePanel">
    <div class="title-search">
        <div class="btn-group">
            <a id="lr-addItem" class="btn btn-default" onclick="btn_AddItem()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-editItem" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-deleteItem" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
            @*<a id="lr-Content" class="btn btn-default" onclick="btn_Content()">&nbsp;设置巡检内容</a>*@
        </div>
        @*<script>$('.btn-group').authorizeButton()</script>*@
    </div>
</div>
<div class="gridPanel" style="width: 100%;padding-left:5px;">
    <table id="gridTable"></table>
    <div id="gridPager"></div>
</div>
